<?php

try
{
	$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;	
	$bdd = new PDO('mysql:host=localhost;dbname=mainbdd', 'root', '', $pdo_options);
	
class Player
{
	private $id;
	
	private $pseudo;
	private $mail;
	private $mdp;
	private $registerdate;
	
	private $gold;
	private $xp;
	private $lvl;
	
	private $total_units;
	private $noAction_units;
	private $working_units;
	private $fighting_units;
	private $training_units;
	private $munitions_units;
	private $recherche_units;
	private $lvl1_units;
	private $lvl2_units;
	private $lvl3_units;
	private $lvl4_units;
	private $lvl5_units;
	
	public function __construct($idMembre)
	{
		$bdd = new PDO('mysql:host=localhost;dbname=mainbdd', 'root', '');
		
		$req_accounts = $bdd->prepare('SELECT * FROM accounts WHERE ID = ?');
		$req_accounts->execute(array($idMembre));
		$req_accounts_fetch = $req_accounts->fetch();
		$req_accounts->closeCursor();
		
		$req_informations = $bdd->prepare('SELECT * FROM informations WHERE ID = ?');
		$req_informations->execute(array($idMembre)); 
		$req_informations_fetch = $req_informations->fetch();
		$req_informations->CloseCursor();
		
		$req_units = $bdd->prepare('SELECT * FROM units WHERE ID = ?');
		$req_units->execute(array($idMembre));
		$req_units_fetch = $req_accounts->fetch();
		$req_units->closeCursor();
		
		$this->pseudo = $req_accounts_fetch['PSEUDO'];
		$this->mdp = $req_accounts_fetch['MDP'];
		$this->mail = $req_accounts_fetch['MAIL'];
		$this->registerdate = $req_accounts_fetch['REGISTERDATE'];
		
		$this->XP = $req_informations_fetch['XP'];
		$this->lvl = $req_informations_fetch['LVL'];
		$this->gold = $req_informations_fetch['GOLD'];
		
		$this->id = $idMembre;
		$this->noAction_units = $req_units_fetch['NOACTION'];
		$this->working_units = $req_units_fetch['WORKING'];
		$this->fighting_units = $req_units_fetch['FIGHTING'];
		$this->training_units = $req_units_fetch['TRAINING'];
		$this->munitions_units = $req_units_fetch['MUNITIONS'];
		$this->recherche_units = $req_units_fetch['RECHERCHE'];
		$this->lvl1_units = $req_units_fetch['LVL1'];
		$this->lvl2_units = $req_units_fetch['LVL2'];
		$this->lvl3_units = $req_units_fetch['LVL3'];
		$this->lvl4_units = $req_units_fetch['LVL4'];
		$this->lvl5_units = $req_units_fetch['LVL5'];		
		$this->total_units = $req_units_fetch['NOACTION'] + $req_units_fetch['WORKING'] + $req_units_fetch['FIGHTING'] + $req_units_fetch['TRAINING'] + $req_units_fetch['MUNITIONS'] + $req_units_fetch['RECHERCHE'];
		
	}//__construct
	
	
	public function getID(){return $this->id;}
	
	public function getPseudo(){return $this->pseudo;}
	public function getMdp(){return $this->mdp;}
	public function getMail(){return $this->mail;}
	public function getRegisterdate(){return $this->registerdate;}
	
	public function getnoAction_units(){return $this->noAction_units;}
	public function getWorking_units(){return $this->working_units;} 
	public function getFighting_units(){return $this->fighting_units;}
	public function getTraining_units(){return $this->training_units;}
	public function getMunitions_units(){return $this->munitions_units;}
	public function getRecherche_units(){return $this->recherche_units;}
	public function getLvl1_units(){return $this->lvl1_units;}
	public function getLvl2_units(){return $this->lvl2_units;}
	public function getLvl3_units(){return $this->lvl3_units;}
	public function getLvl4_units(){return $this->lvl4_units;}
	public function getLvl5_units(){return $this->lvl5_units;}
	
	public function setID($newID){$this->id = $newID;}
	public function setNoAction_units($newNoAction){$this->noAction_units = $newNoAction;}
	public function setWorking_units($newWorking){$this->working_units = $newWorking;}
	public function setFighting_units($newFighting){$this->fighting_units = $newFighting;}
	public function setTraining_units($newTraining){$this->training_units = $newTraining;}
	public function setMunitions_units($newMunition){$this->munitions_units = $newMunitions;}
	public function setRecherche_units($newRecherche){$this->Recherche_units = $newRecherche;}
	public function setLvl1_units($newLvl1){$this->lvl1 = $newLvl1;}
	public function setLvl2_units($newLvl2){$this->lvl2 = $newLvl2;}
	public function setLvl3_units($newLvl3){$this->lvl3 = $newLvl3;}
	public function setLvl4_units($newLvl4){$this->lvl4 = $newLvl4;}
	public function setLvl5_units($newLvl5){$this->lvl5 = $newLvl5;}
	
	public function Total_units()
	{
		$this->total_units = $this->noAction_units + $this->working_units + $this->fighting_units + $this->training_units + $this->munitions_units + $this->recherche_units;
		return $this->total_units;
	}
	
	public function updateBDD()
	{
		$bddc = new PDO('mysql:host=localhost;dbname=mainbdd', 'root', '');
		
		$req_accounts_in = $bddc->prepare('UPDATE accounts set ID = :ID, PSEUDO = :PSEUDO, MDP = :MDP, MAIL = :MAIL, REGISTERDATE = :REGISTERDATE');
		$req_accounts_in->execute(array(
			'ID' => $this->id,
			'PSEUDO' => $this->pseudo,
			'MDP' => $this->mdp,
			'MAIL' => $this->mail,
			'REGISTERDATE' => $this->registerdate ));
			
		$req_informations_in = $bddc->prepare('UPDATE informations set ID = :ID, LVL = :LVL, XP = :XP, GOLD = :GOLD');
		$req_informations_in->execute(array(
			'ID' => $this->id,
			'LVL' => $this->lvl,
			'XP' => $this->XP,
			'GOLD' => $this->gold ));
		
		$req_units_in = $bddc->prepare('UPDATE units set ID = :ID, NOACTION = :NOACTION, WORKING = :WORKING, FIGHTING = :FIGHTING, TRAINING = :TRAINING, MUNITIONS = :MUNITIONS, RECHERCHE = :RECHERCHE, LVL1 = :LVL1, LVL2 = :LVL2, LVL3 = :LVL3, LVL4 = :LVL4, LVL5 = :LVL5');
		$req_units_in->execute(array(
			'ID' => $this->id,
			'NOACTION' => $this->noAction_units,
			'WORKING' => $this->working_units,
			'FIGHTING' => $this->fighting_units,
			'TRAINING' => $this->training_units,
			'MUNITIONS' => $this->munitions_units,
			'RECHERCHE' => $this->recherche_units,
			'LVL1' => $this->lvl1_units,
			'LVL2' => $this->lvl2_units,
			'LVL3' => $this->lvl3_units,
			'LVL4' => $this->lvl4_units,
			'LVL5' => $this->lvl5_units ));
					
	}//updateBDD
	
	
}//fin class Player


}//fin Try
catch (Exception $e)
{
	die('Erreur : ' . $e->getMessage());
}

?>
